/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AccountManager.java
 *
 * Created on 19-Mar-2011, 19:34:13
 */

package inventorymanagement;

import DataAccess.AccessDB;
import DataAccess.DBUtil;
import Entity.EAccount;
import Entity.EncryptionMD5;
import Entity.InfoDatabase;
import com.sun.rowset.CachedRowSetImpl;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author dung
 */
public class AccountManager extends javax.swing.JFrame {
    DefaultTableModel MTableAccount = new DefaultTableModel();
    AccessDB accessDB = new AccessDB();
    InfoDatabase idb = DBUtil.getInfoDB();
    DefaultComboBoxModel dbo = new DefaultComboBoxModel();
    String flag="";
    /** Creates new form AccountManager */
    public AccountManager() {
        initComponents();
        LoadAccount();
        LoadRoleID();
        txtABOD.setEnabled(false);
    }
    private void LoadRoleID(){
        try {
            CachedRowSetImpl rs = accessDB.crsi("select * from Roles");
            rs.execute();
            while (rs.next()) {
                if(!rs.getString(1).equals("AM")){
                cboRole.addItem(rs.getString(2));}
            }
        } catch (SQLException ex) {
            Logger.getLogger(AccountManager.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    private void LoadAccount(){
        accessDB.SelectAccount(MTableAccount);
        int nRows = MTableAccount.getRowCount();
//        if(nRows==0)
//            return;
//        if(nRows>=0)
//        {
//            ListSelectionModel selectionModel = tblAccount.getSelectionModel();
//            selectionModel.setSelectionInterval(0, 0);
////            txtAAccount.setText(tblAccount.getValueAt(nRows, nRows));
//        }
    }
    public void InsertAccount()
    {
        String EAacc = txtAAccount.getText();
        String EApass = EncryptionMD5.encryptMD5("123456");
        String EAFullName = txtAFullName.getText();
        Date dob = txtABOD.getDate();
        String EAaddress = txtAAdđress.getText();
        String EAPhone = txtAPhone.getText();
        String EAemail = txtAEmail.getText();
        String temRole = cboRole.getSelectedItem().toString();
        String sql = "select * from Roles where RoleName='"+temRole+"'";
        CachedRowSetImpl rsrole = accessDB.crsi(sql);
        String Role="";
        try {
            rsrole.execute();
            while(rsrole.next())
            {
                Role = rsrole.getString(1);
            }
        } catch (SQLException ex) {
            Logger.getLogger(AccountManager.class.getName()).log(Level.SEVERE, null, ex);
        }
        boolean Sex = true;
        if(radFemale.isSelected())
        {
            Sex = false;
        }
        EAccount eacc = new EAccount(EAacc, EApass,EAFullName,dob , EAaddress
                , Sex, EAPhone, EAemail, Role, true, false);
        if(flag=="add"){
        accessDB.InsertAccount(eacc);}
        else if(flag=="edit")
        {
            accessDB.updateAccount(eacc);
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btgSex = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtAFullName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        radMale = new javax.swing.JRadioButton();
        radFemale = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        txtAAdđress = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtAPhone = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtAEmail = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtAAccount = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        cboRole = new javax.swing.JComboBox();
        btnAAdd = new javax.swing.JButton();
        btnAEdit = new javax.swing.JButton();
        btnASave = new javax.swing.JButton();
        btnACancel = new javax.swing.JButton();
        btnAResetPass = new javax.swing.JButton();
        txtABOD = new com.toedter.calendar.JDateChooser("MM/dd/yyyy", "##/##/####", '_');
        btnALock = new javax.swing.JButton();
        btnAUnlock = new javax.swing.JButton();
        btnClose = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblAccount = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Account Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18))); // NOI18N
        jPanel1.setOpaque(false);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("FullName:"); // NOI18N

        txtAFullName.setEditable(false);

        jLabel2.setText("Birth Day:"); // NOI18N

        jLabel3.setText("Gender:"); // NOI18N

        btgSex.add(radMale);
        radMale.setSelected(true);
        radMale.setText("Male"); // NOI18N

        btgSex.add(radFemale);
        radFemale.setText("Female"); // NOI18N

        jLabel4.setText("Address:"); // NOI18N

        txtAAdđress.setEditable(false);

        jLabel5.setText("Phone:"); // NOI18N

        txtAPhone.setEditable(false);

        jLabel6.setText("Email:"); // NOI18N

        txtAEmail.setEditable(false);

        jLabel7.setText("Account"); // NOI18N

        txtAAccount.setEditable(false);

        jLabel8.setText("Role"); // NOI18N

        cboRole.setModel(dbo);

        btnAAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/add.jpg"))); // NOI18N
        btnAAdd.setText("Add"); // NOI18N
        btnAAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAAddActionPerformed(evt);
            }
        });

        btnAEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/makeTransfer.png"))); // NOI18N
        btnAEdit.setText("Edit"); // NOI18N
        btnAEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAEditActionPerformed(evt);
            }
        });

        btnASave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/cancel.jpg"))); // NOI18N
        btnASave.setText("Save"); // NOI18N
        btnASave.setEnabled(false);
        btnASave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnASaveActionPerformed(evt);
            }
        });

        btnACancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/cancel.jpg"))); // NOI18N
        btnACancel.setText("Cancel"); // NOI18N
        btnACancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnACancelActionPerformed(evt);
            }
        });

        btnAResetPass.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/a-plus-reset-icon.png"))); // NOI18N
        btnAResetPass.setText("Reset Pasword"); // NOI18N
        btnAResetPass.setEnabled(false);
        btnAResetPass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAResetPassActionPerformed(evt);
            }
        });

        btnALock.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/admin_archive_topics_form.jpg"))); // NOI18N
        btnALock.setText("Lock");
        btnALock.setEnabled(false);
        btnALock.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnALockActionPerformed(evt);
            }
        });

        btnAUnlock.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/unlock.png"))); // NOI18N
        btnAUnlock.setText("Unlock");
        btnAUnlock.setEnabled(false);
        btnAUnlock.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAUnlockActionPerformed(evt);
            }
        });

        btnClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/logout2.jpg"))); // NOI18N
        btnClose.setText("Close");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtAAccount)
                    .addComponent(txtAEmail)
                    .addComponent(txtAPhone)
                    .addComponent(txtAAdđress)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(radMale)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(radFemale))
                    .addComponent(txtAFullName, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(txtABOD, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cboRole, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(524, 524, 524))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAResetPass)
                    .addComponent(btnAAdd)
                    .addComponent(btnACancel))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnALock)
                        .addGap(41, 41, 41))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(btnAEdit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnAUnlock)
                    .addComponent(btnASave)
                    .addComponent(btnClose))
                .addContainerGap(504, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtAFullName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(txtABOD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(radMale)
                    .addComponent(radFemale))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAAdđress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtAPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtAEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtAAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(cboRole, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAAdd)
                    .addComponent(btnASave)
                    .addComponent(btnAEdit))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAResetPass)
                    .addComponent(btnAUnlock)
                    .addComponent(btnALock))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnClose)
                    .addComponent(btnACancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel3.setPreferredSize(new java.awt.Dimension(876, 174));
        jPanel3.setVerifyInputWhenFocusTarget(false);

        tblAccount.setModel(MTableAccount);
        tblAccount.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblAccountMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblAccount);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 872, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAAddActionPerformed
        // TODO add your handling code here:
        btnAAdd.setEnabled(false);
        btnAEdit.setEnabled(false);
        btnACancel.setEnabled(true);
        btnAUnlock.setEnabled(false);
        btnALock.setEnabled(false);
        btnAResetPass.setEnabled(false);
        btnASave.setEnabled(true);
        txtAFullName.setEditable(true);
        txtAAdđress.setEditable(true);
        txtAEmail.setEditable(true);
        txtAPhone.setEditable(true);
        txtAAccount.setEditable(true);
        flag="add";
        txtABOD.setEnabled(true);
        txtAAccount.setText("");
        txtAAdđress.setText("");
        txtAFullName.setText("");
        txtAPhone.setText("");
        txtAEmail.setText("");
        txtABOD.setDate(null);
        
//        System.out.println(eacc.getAddress());
    }//GEN-LAST:event_btnAAddActionPerformed

    private void btnAUnlockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAUnlockActionPerformed
        // TODO add your handling code here:
        accessDB.LockAccount(true, txtAAccount.getText(),null,"Are you want unlock this account?","Unlock Account");
        accessDB.RefeshAccount(tblAccount);
    }//GEN-LAST:event_btnAUnlockActionPerformed

    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnCloseActionPerformed

    private void btnASaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnASaveActionPerformed
        // TODO add your handling code here:
        InsertAccount();
        accessDB.RefeshAccount(tblAccount);
    }//GEN-LAST:event_btnASaveActionPerformed

    private void btnACancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnACancelActionPerformed
        // TODO add your handling code here:
        btnAAdd.setEnabled(true);
        btnAEdit.setEnabled(true);
        btnACancel.setEnabled(true);
        btnASave.setEnabled(false);
    }//GEN-LAST:event_btnACancelActionPerformed

    private void btnAEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAEditActionPerformed
        // TODO add your handling code here:
         btnAAdd.setEnabled(false);
        btnAEdit.setEnabled(false);
        btnACancel.setEnabled(true);
        btnASave.setEnabled(true);
        txtAFullName.setEditable(true);
        txtAAdđress.setEditable(true);
        txtAEmail.setEditable(true);
        txtAPhone.setEditable(true);
        flag="edit";
    }//GEN-LAST:event_btnAEditActionPerformed

    private void btnALockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnALockActionPerformed
        // TODO add your handling code here:
        accessDB.LockAccount(false, txtAAccount.getText(),null,"Are you want to lock this account?","Lock Account");
        accessDB.RefeshAccount(tblAccount);
    }//GEN-LAST:event_btnALockActionPerformed

    private void tblAccountMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblAccountMouseClicked
        // TODO add your handling code here:
        int i = tblAccount.getSelectedRow();
        txtAAccount.setText(String.valueOf(tblAccount.getValueAt(i, 1)));
        txtAAdđress.setText(String.valueOf(tblAccount.getValueAt(i, 5)));
        txtABOD.setDate((Date) tblAccount.getValueAt(i,3));
        txtAFullName.setText(String.valueOf(tblAccount.getValueAt(i, 2)));
        txtAEmail.setText(String.valueOf(tblAccount.getValueAt(i, 7)));
        txtAPhone.setText(String.valueOf(tblAccount.getValueAt(i, 6)));
        String active = String.valueOf(tblAccount.getValueAt(i, 9));
        String roleid=String.valueOf(tblAccount.getValueAt(i, 8));
       
        if(active=="true")
        {
            btnALock.setEnabled(true);
            btnAUnlock.setEnabled(false);
        }
        else if(active=="false"&&roleid!="AM"){
            btnALock.setEnabled(false);
            btnAUnlock.setEnabled(true);
        }
         if(((roleid.equals("AM"))))
        {
            btnAUnlock.setEnabled(false);
            btnALock.setEnabled(false);
        }
        btnAResetPass.setEnabled(true);
    }//GEN-LAST:event_tblAccountMouseClicked

    private void btnAResetPassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAResetPassActionPerformed
        // TODO add your handling code here:
        String message = "Are You Want to Reset Password";
        String title = "Reset Password";
        accessDB.LockAccount(true,txtAAccount.getText(), EncryptionMD5.encryptMD5("123456"),message,title);
    }//GEN-LAST:event_btnAResetPassActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AccountManager().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btgSex;
    private javax.swing.JButton btnAAdd;
    private javax.swing.JButton btnACancel;
    private javax.swing.JButton btnAEdit;
    private javax.swing.JButton btnALock;
    private javax.swing.JButton btnAResetPass;
    private javax.swing.JButton btnASave;
    private javax.swing.JButton btnAUnlock;
    private javax.swing.JButton btnClose;
    private javax.swing.JComboBox cboRole;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JRadioButton radFemale;
    private javax.swing.JRadioButton radMale;
    private javax.swing.JTable tblAccount;
    private javax.swing.JTextField txtAAccount;
    private javax.swing.JTextField txtAAdđress;
    private com.toedter.calendar.JDateChooser txtABOD;
    private javax.swing.JTextField txtAEmail;
    private javax.swing.JTextField txtAFullName;
    private javax.swing.JTextField txtAPhone;
    // End of variables declaration//GEN-END:variables

}
